package top.chj.day19.collection;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Objects;

/**
 * @Auther:小陈的Java
 */
public class Test1 {
    @Test
    public void test1(){
        Collection collection = new ArrayList();
        collection.add(1);
        collection.add("haha");
        Collection collection1 = new ArrayList();
        collection1.add("A");
        collection1.add("B");
        collection1.addAll(collection1);
    }
    @Test
    public void test2(){
        Collection collection = new ArrayList();
        collection.add("a");
        collection.add("b");
        collection.add("A");
        collection.add("B");
        System.out.println(collection.size());
        System.out.println(collection.isEmpty());
        System.out.println(collection.contains("c"));
        Collection<String > c = new ArrayList<>();
        c.add("a");
        c.add("b");
        System.out.println(collection.contains(c));
    }
    @Test
    public void test3(){
        Collection<User> users = new ArrayList<>();
        User user1 = new User(1,"张三",18);
        User user2 = new User(2,"李四",19);
        User user3 = new User(3,"王五",18);
        users.add(user1);
        users.add(user2);
        users.add(user3);
        System.out.println(users.contains(new User(1,"张三",18)));
    }
    @Test
    public void test4(){
        Collection<String> cc = new ArrayList<>();
        cc.add("a");
        cc.add("b");
        cc.add("c");
        cc.remove("a");
        System.out.println(cc);
        Collection<String> c = new ArrayList<>();
        c.add("a");
        c.add("b");
        cc.removeAll(c);
        System.out.println(cc);
        cc.clear();
        System.out.println(cc);
    }
    @Test
    public void test5(){
        Collection<String> cc = new ArrayList<>();
        cc.add("a");
        cc.add("b");
        cc.add("c");
        Object[] objects = cc.toArray();
        for (Object obj : objects){
            System.out.println(obj);
        }
    }
    @Test
    public void tes6(){
        Collection<String> cc = new ArrayList<>();
        cc.add("a");
        cc.add("b");
        cc.add("c");
        Collection<String> c = new ArrayList<>();
        c.add("a");
        c.add("b");
        System.out.println(cc.retainAll(c));
        System.out.println(cc.equals(c));
    }

}
class User{
    private int id;
    private String name;
    private int age;

    public User(int id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        User user = (User) o;
        return id == user.id &&
                age == user.age &&
                Objects.equals(name, user.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name, age);
    }
}